package com.link.server.ws.handle;

import com.link.common.packet.RequestOperate;
import com.link.database.entity.DBAccount;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.util.AttributeKey;

import java.io.IOException;

public interface  Handler {
    public static final AttributeKey<DBAccount> ACCOUNT_KEY=AttributeKey.valueOf("account");
    public static final AttributeKey<String> VERIFICATION_CODE_KEY=AttributeKey.valueOf("verificationCode");
    public static final AttributeKey<String> TOKEN_KEY=AttributeKey.valueOf("token");
    public   void invoke(RequestOperate operate, ByteBuf packet, ChannelHandlerContext ctx) throws  Exception;
    default void send(ChannelHandlerContext ctx,ByteBuf buffer) throws IOException {
        ctx.channel().writeAndFlush(new BinaryWebSocketFrame(ctx.alloc().buffer().writeBytes(buffer)));
        buffer.release();
    }
}
